﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Data.Linq;
using System.Text;
using Biz_Dal.Dal;

namespace Biz_Dal.Biz
{
    public class BizCTDonDatHang
    {
        

        private int idCTDDH;

        public int IdCTDDH
        {
            get { return idCTDDH; }
            set { idCTDDH = value; }
        }


        private int soLuongDH;

        public int SoLuongDH
        {
            get { return soLuongDH; }
            set { soLuongDH = value; }
        }

        private double donGia;

        public double DonGia
        {
            get { return donGia; }
            set { donGia = value; }
        }

        public double ThanhTien
        {
            set { }
            get { return donGia * soLuongDH; }
        }

        private int idDDH;

        public int IdDDH
        {
            get { return idDDH; }
            set
            {
                idDDH = value;
                donDatHang = new BizDonDatHang(idDDH);
            }
        }

        private BizDonDatHang donDatHang;

        public BizDonDatHang DonDatHang
        {
            get 
            {
                if (donDatHang == null)
                    donDatHang = new BizDonDatHang(IdSach);
                return donDatHang; 
            }
            set { donDatHang = value; }
        }

        private int _idSach;

        public int IdSach
        {
            get { return _idSach; }
            set 
            {
                _idSach = value;
                sach = new BizSach(_idSach);
            }
        }

        private BizSach sach;

        public BizSach Sach
        {
            get 
            {
                if (sach == null)
                    sach = new BizSach(IdSach);
                return sach; 
            }
            set { sach = value; }
        }

        public string TenSach
        {
            get { return sach.tenSach; }
        }

        public Binary HinhSach
        {
            get
            {
                return sach.hinhSach;
            }
        }

        public string MaSach
        {
            get
            {
                return sach.maSach;
            }
        }

        public BizCTDonDatHang(int _id)
        {

        }

        public BizCTDonDatHang(int _id, int idDDH,int idSach,int soluong,double dongia)
        {
            IdCTDDH = _id;
            IdDDH = idDDH;
            IdSach = idSach;
            soLuongDH = soluong;
            DonGia = dongia;
            ThanhTien = soluong * dongia;
        }

        public void Insert()
        {
            DalCTDonDatHang.Insert(this);
        }

        public static int IdMaxCTDDH()
        {
            try
            {
                return DalCTDonDatHang.IdMaxCTDDH();
            }
            catch
            {
                throw new Exception("Error!");
            }
        }

        public static List<BizCTDonDatHang> GetChiTietDonDatHangByIDDDH(int id)
        {
            try
            {
                return DalCTDonDatHang.GetChiTietDonDatHangByIDDDH(id);
            }
            catch
            {
                throw new Exception("Error!");
            }
        }
    }
}
